package com.app.micaihu.custom.components;

import android.view.View;
import android.widget.AdapterView;

/**
 * 一定时间内不能连续点击的Item单击监听事件
 * Created by linkai on 2016/10/28.
 */
public abstract class NoDoubleItemClickListener implements AdapterView.OnItemClickListener {

    public static final int MIN_CLICK_DELAY_TIME = 500;
    private long lastClickTime = 0;


    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        long currentTime = System.currentTimeMillis();
        //如果连续点击的时间小于 MIN_CLICK_DELAY_TIME  则本次点击不起效
        if (currentTime - lastClickTime > MIN_CLICK_DELAY_TIME) {
            lastClickTime = currentTime;
            onNoDoubleItemClick(view);
        }
    }

    /**
     * 不能连续点击的虚方法
     * @param v
     */
    public abstract void onNoDoubleItemClick(View v);
}
